package com.cycleit.applicationexample.responder {
	import com.cycleit.applicationexample.model.ExampleResponseModel;
	
	public class FacadeResponder extends GenericResponder{
		private var _model:Object;
		
		public function FacadeResponder(_model:Object){
			this._model = _model;
		}
		
		override public function result(r:Object):void{
			var idVar:String = r.token.message.operation + "Data";
			if(r.result){
				_model[decapitalize(idVar)] = r.result;
			}
			ExampleResponseModel.getInstance().message = "Ok";
			ExampleResponseModel.getInstance().flagMessageOk = true;
			ExampleResponseModel.getInstance().flagMessage = !ExampleResponseModel.getInstance().flagMessage;
		} 
		
		override public function fault(f:Object):void{
			ExampleResponseModel.getInstance().message = "Ko";
			ExampleResponseModel.getInstance().flagMessageOk = false;
			ExampleResponseModel.getInstance().flagMessage = !ExampleResponseModel.getInstance().flagMessage;
		}
		
		private function decapitalize(value:String):String{
			var res:String = "";
			if(value.length>0){
				var aux:String = value.substring(0,1);
				var aux2:String = "";
				if(value.length > 1){
					aux2 = value.substring(1,value.length);
				}
				res = aux.toLocaleLowerCase() + aux2;
			}
			return res;
		} 
		
	}
}